package cn.edu.yzu.scholarship.config;

import cn.edu.yzu.scholarship.controller.ExportCtrler;
import cn.edu.yzu.scholarship.controller.GrantCtrler;
import cn.edu.yzu.scholarship.controller.ImportCtrler;
import cn.edu.yzu.scholarship.controller.MenuCtrler;
import cn.edu.yzu.scholarship.controller.UniCtrler;
import cn.edu.yzu.scholarship.controller.UserCtrler;
import cn.edu.yzu.scholarship.interceptor.AuthCheckInterceptor;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.plugin.sqlinxml.SqlInXmlPlugin;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

public class ScholarshipJFinalConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setViewType(ViewType.JSP);
		me.setError404View("/error/404.html");
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/user",UserCtrler.class);
		me.add("/menu",MenuCtrler.class);
		me.add("/uni",UniCtrler.class);
		me.add("/export",ExportCtrler.class);
		me.add("/grant",GrantCtrler.class);
		me.add("/import",ImportCtrler.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		this.loadPropertyFile("web.properties");
		C3p0Plugin cp = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"));
		me.add(cp);
		me.add(new ActiveRecordPlugin(cp));
		me.add(new SqlInXmlPlugin());
	}

	@Override
	public void configInterceptor(Interceptors me) {
		me.add(new AuthCheckInterceptor());
	}

	@Override
	public void configHandler(Handlers me) {
	}

}
